package day02;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @Description: TODO
 * @Author: ZYX
 * @Date: 2022/2/9 14:54
 * @Version: 1.0
 */
public class Demo04 {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<String> streamSource = env.fromElements("white", "black", "green", "pink");

        streamSource.flatMap(new FlatMapFunction<String, String>() {
            @Override
            public void flatMap(String value, Collector<String> result) throws Exception {
                if ("white".equalsIgnoreCase(value)){
                    result.collect(value);
                }else if ("green".equalsIgnoreCase(value)){
                    result.collect(value);
                    result.collect(value);
                }
            }
        }).print();

        env.execute();

    }

}
